VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "IScreen_LevelComplete"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'====================================================================================
'clsScreen_LevelComplete
'====================================================================================
Option Explicit

'This is a snap-in class for `Project.GameScreen`, shown on screen
Implements IScreen

'------------------------------------------------------------------------------------
Private TitleText As String               '"Level Complete!" text
Private ScoreCount As Long                'Counts up to the score got on the level
Private GhostCount As Long                'Counts up the number of ghosts eaten
Private TimeCount As Long                 'Counts up the time taken on the level

Private ScoreRank As Long                 'Where you ranked for score on this level
Private TimeRank As Long                  'Where you ranked for time on this level

Private MarX As Long                      'Mar's location on the screen

'--- Graphics -----------------------------------------------------------------------
Private Background As New clsScrollingBG  'The scrolling background
Private MenuBuffer As New ImageTGA        'Buffer for clipping the text

'====================================================================================
'CLASS Initialize
'====================================================================================
Private Sub Class_Initialize()
    'Setup the scrolling background (Use the same background as the completed level)
    Background.Initialize Level.Data.Theme, -2, 1
    TitleText = "Level Complete!"
    
    'The extra buffer is needed so that we can clip the text as Pac Mar eats it
    MenuBuffer.Create 450, Fonts.Menu.LetterHeight
    Fonts.Pastel.DrawText MenuBuffer.hDC, 0, 3, "Total:", 2
    Fonts.Menu.DrawText MenuBuffer.hDC, 210, 0, Game.Score, 2
    
    'Hide Mar off the left of the screen
    MarX = -64
    
    'Did you get a level-specific high score?
    ScoreRank = Level.Data.HighScores.BestScores.Rank(Level.StatsPointsEarnt, Level.StatsTimeTaken, PM_RANKBY_SCORE)
    TimeRank = Level.Data.HighScores.BestTimes.Rank(Level.StatsPointsEarnt, Level.StatsTimeTaken, PM_RANKBY_TIME)
    
    'Start animation control
    GameMedia.Particles.ClearAll
    GameMedia.Particles.OffsetX = 0: GameMedia.Particles.OffsetY = 0
    ScreenMode = SM_Load
End Sub

'====================================================================================
'ISCREEN Animate: Animate this screen
'====================================================================================
Private Sub IScreen_Animate()
    Static C As Long
    
    '--- Load -----------------------------------------------------------------------
    If ScreenMode = SM_Load Then
        Select Case ModeStep
            Case 0
                'When loading the title screen, slide open the doors
                If Status.OpenDoors(STATUS_SPEED_STANDARD) Then ModeStep = 1
                
            Case 1
                If (Frame.Count Mod 2) = 0 Then
                    C = C + 1
                    ScoreCount = Range(ScoreCount + 250, 0, Level.StatsPointsEarnt)
                    If ScoreCount = Level.StatsPointsEarnt Then C = 0: ModeStep = 2
                    If (ScoreCount > 0) Then Randomize: GameMedia.Particles.Create PT_COOKIE1 + (C Mod 1), (370 + Rnd(1) * 40), 240, 45
                End If
                
            Case 2
                C = C + 1
                If (C Mod 10 = 0) Then
                    GhostCount = Range(GhostCount + 1, 0, Level.StatsGhostsEaten)
                    If GhostCount = Level.StatsGhostsEaten Then C = 0: ModeStep = 3
                    If GhostCount > 0 Then Randomize: GameMedia.Particles.Create PT_HEART, (360 + Rnd(1) * 20), 275, 384
                End If
                
            Case 3
                TimeCount = Range(TimeCount + 2, 0, Level.StatsTimeTaken)
                If TimeCount = Level.StatsTimeTaken Then
                    C = C + 1: If C = 32 Then C = 0: ModeStep = 4
                End If
            
            Case 4
                C = C + 1: If C = 32 Then C = 0: ModeStep = 5
                
            Case 5
                MarX = (MarX + 9): If MarX > 640 Then ScreenMode = SM_Exit
                
        End Select
    
    '--- Exit -----------------------------------------------------------------------
    ElseIf ScreenMode = SM_Exit Then
        If ModeStep = 0 Then
            'Close the doors...
            If Status.CloseDoors(STATUS_SPEED_STANDARD) Then ModeStep = 1
        
        ElseIf ModeStep = 1 Then
            'Load the next level
            GameMedia.Particles.ClearAll
            Game.NextLevel
            '!//TODO: Load level high score screen, if a new high score for that _
                      level.
            
        End If
        
    End If
    
    'Animate Mar
    If (Frame.Count Mod 3) = 0 Then Sprites.Mar(MA_Right).Animate
    
    'Scroll the background
    Background.Animate
End Sub

'====================================================================================
'ISCREEN Render: Draw the screen
'====================================================================================
Private Sub IScreen_Render(ByVal hDC As Long)
    Dim X As Long, Y As Single, K As Long
    Dim cMarX As Long
    Dim tLeft As Long
    Static p As Long
    
    'Draw the scrolling background
    Background.Render hDC
    
    'Draw on the bouncy Level Complete sign
    X = 85: For K = 1 To Len(TitleText)
        Y = 180 + (Cos((K + p) * 0.2) * 10)
        X = X + Fonts.Menu.DrawText(hDC, X, Y, Mid(TitleText, K, 1), 2)
    Next K
    p = p + 1
    
    'Draw the Pac Mar logo on the main screen
    GameMedia.DrawPacMarTitle hDC, 48
    
    'Draw on text according to Mode Step animation control
    If (ModeStep >= 1) Or (ScreenMode = SM_Exit) Then
        Fonts.Pastel.DrawText hDC, 150, 250, "Points:", Abs(ModeStep = 1) + 1
        Fonts.Pastel.DrawText hDC, 360, 250, "+" & ScoreCount, Abs(ModeStep = 1) + 1
    End If
    If (ModeStep >= 2) Or (ScreenMode = SM_Exit) Then
        Fonts.Pastel.DrawText hDC, 150, 280, "Ghosts Eaten:", Abs(ModeStep = 2) + 1
        Fonts.Pastel.DrawText hDC, 360, 280, "x" & GhostCount, Abs(ModeStep = 2) + 1
    End If
    If (ModeStep >= 3) Or (ScreenMode = SM_Exit) Then
        'Time Taken:
        Fonts.Pastel.DrawText hDC, 150, 310, "Time Taken:", Abs(ModeStep = 3) + 1
        GameText.DrawTime TimeCount, Fonts.Pastel, hDC, 360, 310, (ModeStep = 3)
    End If
    If ModeStep >= 4 Then
        cMarX = MarX + 36
        tLeft = Range(cMarX, 150, 640)
        MenuBuffer.DrawEx hDC, tLeft, 354, MenuBuffer.Width - (tLeft - 150), MenuBuffer.Height, (tLeft - 150), 0
    End If
    
    'Draw Pac Mar on the screen
    Sprites.Mar(MA_Right).Draw hDC, MarX, 336
    
End Sub

'====================================================================================
'ISCREEN RenderTopBar: Render the top status bar display
'====================================================================================
Private Sub IScreen_RenderTopBar(ByVal hDC As Long)
    'This screen does not use the top status bar. This function has to be here in
    'order to comply with the IScreen Interface 'IScreen.cls'
End Sub

'====================================================================================
'ISCREEN RenderBottomBar: Render the bottom status bar display
'====================================================================================
Private Sub IScreen_RenderBottomBar(ByVal hDC As Long)
    'This screen does not use the bottom status bar. This function has to be here
    'in order to comply with the IScreen Interface 'IScreen.cls'
End Sub

'====================================================================================
'ISCREEN HandleKey
'====================================================================================
Private Sub IScreen_HandleKey(ByVal KeyCode As Integer, ByVal Shift As Integer)
    'This screen doesn't accept key presses. This function has to be here in order
    'to comply with the IScreen Interface 'IScreen.cls'
End Sub

'====================================================================================
'ISCREEN HandleMouseMove
'====================================================================================
Private Sub IScreen_HandleMouseMove(ByVal MouseX As Single, ByVal MouseY As Single)
    'This screen ignores mouse movements. This function has to be here in order to
    'comply with the IScreen Interface 'IScreen.cls'
End Sub

'====================================================================================
'ISCREEN HandleMouseClick
'====================================================================================
Private Sub IScreen_HandleMouseClick(ByVal Button As Integer, ByVal Shift As Integer, ByVal MouseX As Integer, ByVal MouseY As Integer)
    'This screen ignores mouse clicks. This function has to be here in order to
    'comply with the IScreen Interface 'IScreen.cls'
End Sub

'====================================================================================
'CLASS Terminate: Free up memory when the screen is unloaded
'====================================================================================
Private Sub Class_Terminate()
    Set MenuBuffer = Nothing
    Set Background = Nothing
End Sub

'=== END ============================================================================
'This work is licenced under the Creative Commons Attribution 2.5 License
